package com.example.cinemasystemv2.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.time.LocalDateTime;

@Entity
@Table(name = "orders")
public class Order {
    @Id
    private String orderId;
    
    @Column(name = "username", nullable = false)
    private String username;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "screening_id", nullable = false)
    @JsonIgnore
    private Screening screening;
    
    @Column(name = "row_num", nullable = false)
    private int row;
    
    @Column(name = "seat_num", nullable = false)
    private int seat;
    
    @Column(name = "amount", nullable = false)
    private double amount;
    
    @Column(name = "orderTime", nullable = false)
    private LocalDateTime orderTime;
    
    @Column(name = "isRefunded")
    private boolean isRefunded;
    
    @Column(name = "refundTime")
    private LocalDateTime refundTime;
    
    @Column(name = "refundAmount")
    private double refundAmount;
    
    @Column(name = "status", nullable = false)
    private String status = "pending"; // 默认状态为待处理
    
    @Column(name = "ticket_count")
    private int ticketCount = 1; // 票数，默认为1

    // 默认构造函数
    public Order() {}
    
    // 带参构造函数
    public Order(String orderId, String username, Screening screening, int row, int seat, 
                 double amount, LocalDateTime orderTime) {
        this.orderId = orderId;
        this.username = username;
        this.screening = screening;
        this.row = row;
        this.seat = seat;
        this.amount = amount;
        this.orderTime = orderTime;
        this.isRefunded = false;
        this.status = "pending";
    }
    
    // Getters and Setters
    public String getOrderId() {
        return orderId;
    }
    
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public Screening getScreening() {
        return screening;
    }
    
    public void setScreening(Screening screening) {
        this.screening = screening;
    }
    
    public int getRow() {
        return row;
    }
    
    public void setRow(int row) {
        this.row = row;
    }
    
    public int getSeat() {
        return seat;
    }
    
    public void setSeat(int seat) {
        this.seat = seat;
    }
    
    public double getAmount() {
        return amount;
    }
    
    public void setAmount(double amount) {
        this.amount = amount;
    }
    
    public LocalDateTime getOrderTime() {
        return orderTime;
    }
    
    public void setOrderTime(LocalDateTime orderTime) {
        this.orderTime = orderTime;
    }
    
    public boolean isRefunded() {
        return isRefunded;
    }
    
    public void setRefunded(boolean refunded) {
        isRefunded = refunded;
    }
    
    public LocalDateTime getRefundTime() {
        return refundTime;
    }
    
    public void setRefundTime(LocalDateTime refundTime) {
        this.refundTime = refundTime;
    }
    
    public double getRefundAmount() {
        return refundAmount;
    }
    
    public void setRefundAmount(double refundAmount) {
        this.refundAmount = refundAmount;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public int getTicketCount() {
        return ticketCount;
    }
    
    public void setTicketCount(int ticketCount) {
        this.ticketCount = ticketCount;
    }
}